package org.lixf.controller;

import org.lixf.biz.DepartmentBiz;
import org.lixf.biz.EmployeeBiz;
import org.lixf.entity.Employee;
import org.lixf.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeBiz employeeBiz;

    @Autowired
    private DepartmentBiz departmentBiz;

    @RequestMapping("/list")
    public String list(Map<String, Object> map){
        map.put("list", employeeBiz.getAll());
        return "employee_list";
    }
    @RequestMapping("/to_add")
    public String toAdd(Map<String, Object> map){
        map.put("employee", new Employee());
        map.put("dlist", departmentBiz.getAll());
        map.put("plist", Constants.getPosts());
        return "employee_add";
    }
    @RequestMapping("/add")
    public String add(Employee employee){
        employeeBiz.add(employee);
        return "redirect:/employee/list";
    }
    @RequestMapping("/to_update")
    public String toUpdate(String sn, Map<String, Object> map){
        map.put("employee", employeeBiz.get(sn));
        map.put("dlist", departmentBiz.getAll());
        map.put("plist", Constants.getPosts());
        return "employee_update";
    }
    @RequestMapping("/update")
    public String update(Employee employee){
        employeeBiz.edit(employee);
        return "redirect:/employee/list";
    }
    @RequestMapping("/remove")
    public String remove(String sn){
        employeeBiz.remove(sn);
        return "redirect:/employee/list";
    }
}
